<!-- 公用菜单组件 
    该组件注意事项：
    1、有三级菜单的页面需要在src/data/menuNav.js里面定义
-->

<template>
    <el-menu
        :default-active="setActive"
        class="menu-wrap"
        router
        unique-opened
        :background-color="color.bgColor2"
        :text-color="color.textColor2"
        :active-text-color="color.textColor">
        <el-submenu v-for="(data, i) in menuData" :key="data.url" :index="data.name">
            <template slot="title">
                <i :class="['iconfont', data.icons]"></i>
                <span>{{ data.name }}</span>
            </template>
            <el-menu-item v-for="item in data.sublist" :key="item.url" :index="item.url">{{ item.name }}</el-menu-item>
        </el-submenu>
    </el-menu>
</template>

<script>

import { menuList } from '@/service/getData'
import getResourceList from '@/data/getResourceList'
import menuNav from '@/data/menuNav'
import color from '@/config/color'

export default {
    name: 'menuList',
    data () {
        return {
            color: color,
            menuData: []
        }
    },
    created() {
        this.initData();
    },
    methods: {
        // 获取菜单数据
        async initData() {
            let that = this,
                // res = await menuList();
                res = getResourceList;

            if (res.retStatus == responseStatus.ok) {
                that.menuData = res.retBody.list;
            }
            // console.log('menuData', that.menuData);
        }
    },
    computed: {
        // 设置当前页面高亮
        setActive() {
            let now = this.$route.path,
                result = now;
            // 有三级菜单的设置三级菜单页面高亮
            for (var i in menuNav) {
                if (menuNav[i]['path'].includes(now)) {
                    result = menuNav[i]['path'][0];
                }
            }
            return result;
        }
    }
}
</script>

<style lang="less" scoped>
    @import '../assets/css/base.less';
    .menu-wrap:not(.el-menu--collapse) {
        width: 150px;
        overflow: hidden;
    }
    .el-submenu__title {
        height: 64px;
        line-height: 64px;
    }
    .iconfont {
        margin-right: 5px;
        font-size: 22px;
        color: @textColor2;
    }
</style>